﻿<%@ WebHandler Language="C#" Class="hesuan_shigong_luji_shuini" %>

using System.Web;
using KeaoBase;
using ServiceStack.Redis;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System;

public class hesuan_shigong_luji_shuini : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        try
        {
            string uid = context.Request.QueryString["uid"];
            string kid = context.Request.QueryString["kid"];
            if (!Auth.UserLogined(uid, kid))
            {
                context.Response.Write("[]");
                return;
            }
            string key = KeaoUtils.GetMD5Str(context.Request.Url.OriginalString.Replace(uid,"cache").Replace(kid,"cache"));
            using (IRedisClient redis = RedisClientPool.GetReadOnlyRedisClient())
            {
                if (redis != null)
                {
                    if (redis.ContainsKey(key))
                    {
                        context.Response.Write(redis.GetValue(key));
                        return;
                    }
                }
            }
            BaseDataBase m_DB = System.Reflection.Assembly.Load("KeaoDataBase").CreateInstance(string.Format("KeaoDataBase.{0}", ConfigurationManager.AppSettings["数据库类型"])) as BaseDataBase;
            if (!m_DB.InitDataBase(ConfigurationManager.ConnectionStrings["DataSource"].ConnectionString))
            {
                context.Response.Write("[]");
                return;
            }
            else
            {
                string kaishi = context.Request.QueryString["kaishi"];
                string jieshu = context.Request.QueryString["jieshu"];
                string gonglihao1 = context.Request.QueryString["gonglihao1"];
                string dian1 = context.Request.QueryString["dian1"];
                string gonglihao2 = context.Request.QueryString["gonglihao2"];
                string dian2 = context.Request.QueryString["dian2"];
                string zhandian = context.Request.QueryString["zhandian"];

                object param1 = m_DB.CreateParamter("@kaishi", string.Format("{0} 00:00:00", kaishi),false);
                object param2 = m_DB.CreateParamter("@jieshu", string.Format("{0} 23:59:59", jieshu), false);
                object param3 = m_DB.CreateParamter("@zhandian", string.Format("{0}", zhandian),false);
                DataSet Ds = m_DB.ExecuteTableProcedure("P_ShuiWenLiao_ShuiNiShiGong", new object[] {param1,param2,param3 });

                if (Ds!=null&&Ds.Tables.Count>0&&Ds.Tables[0].Rows.Count > 0)
                {
                    string responseJson = KeaoUtils.Dt2Json(Ds.Tables[0]);
                    using (IRedisClient redis = RedisClientPool.GetRedisClient())
                    {
                        if (redis != null)
                        {
                            redis.SetValue(key, responseJson, TimeSpan.FromMinutes(10.0));
                        }
                    }
                    context.Response.Write(responseJson);
                }
                else
                {
                    context.Response.Write("[]");
                }
            }
        }
        catch (Exception err)
        {
            KeaoUtils.LogTxt(string.Format("路基施工水泥查询异常。{0}", err.Message));
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}